Conversation
There was a problem hiding this comment.
Pull Request Overview
The PR refactors bmi_waves.c to replace repetitive per-variable logic with a centralized VarInfo table and lookup function.
- Introduces
VarInfostruct and a staticvariables[]table to centralize metadata. - Adds
find_variable()for DRY lookups inget_var_type,get_var_units,get_var_itemsize, andget_var_location. - Cleans up function brace styles and removes long chains of
if/else.
Comments suppressed due to low confidence (4)
bmi_waves.c:15
- [nitpick] The field name
typeis generic; consider renaming it todata_typeto clarify its purpose and avoid confusion with C/C++ keywords.
const char *type;
bmi_waves.c:312
- Consider adding unit tests for the variable getters (type, units, itemsize, location) to cover both valid and invalid names, ensuring error paths are handled correctly.
const VarInfo *var = find_variable(name);
bmi_waves.c:59
- [nitpick] Indentation here mixes tabs and spaces; align with the project style (e.g., spaces only) to improve consistency.
size_t i;
bmi_waves.c:60
- This linear search may become a bottleneck if
variablesgrows large; consider using a lookup table or hash map for O(1) lookup.
for (i = 0; i < VAR_COUNT; i++) {
| /* Implement this: Add model-specific includes */ | ||
| #include "waves_model.h" | ||
|
|
||
|
|
There was a problem hiding this comment.
Add a brief comment explaining the VarInfo struct and its purpose for improved code readability.
Suggested change
| /* | |
| * VarInfo is a structure used to store metadata about a variable. | |
| * - name: The name of the variable. | |
| * - units: The units in which the variable is measured. | |
| * - type: The data type of the variable (e.g., "double"). | |
| * - itemsize: The size of one item of the variable's type, in bytes. | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've cleaned up the
bmi_waves.c. It now uses a table of variables that lists variable names and metadata.